% Archivo para limpiar
%Origen balusel
%German Mondragon.
%

function [fsel] = norm_sfs(fT,dT)

N = length(dT);

    f = fT;
    d = dT;

s = std(f);
ii = find(s>1e-8);
f  = f(:,ii);  
fT = fT(:,ii);

p = 1:size(f,2);

% eliminating correlated features

C = abs(corrcoef(f));
[ii,jj] = find(C>0.9999);
if (not(isempty(ii)))
    for i=1:length(ii)
        if (abs(ii(i)-jj(i))>0)
            k = max([ii(i) jj(i)]);
            t = find(p==k);
            n = length(p);
            if (not(isempty(t)))
                if (t==1)
                    p = p(2:n);
                else
                    if (t==n)
                        p = p(1:n-1);
                    else
                        p = p([1:t-1 t+1:n]);
                    end
                end
            end
        end
    end
end
f  = f(:,p);
fT = fT(:,p);



[ff,a,b] = normalize(f,1);
fT = fT.*(ones(N,1)*a) + ones(N,1)*b;



fsel = ff;

%drawnow